#include <iostream>
#include <vector>
#include <algorithm>
#define MAXN 10005
#define MAXM 20005
using namespace std;
int N, M;
int par[MAXN], ranks[MAXN];

int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (ranks[x] < ranks[y]) par[x] = y;
    else {
        par[y] = x;
        if (ranks[x] == ranks[y]) ranks[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

struct Edge {
    int from, to, cost;
};

bool operator<(const Edge & e1, const Edge & e2) {
    return e1.cost < e2.cost;
}


Edge edges[MAXM];
void solve();
int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> edges[i].from >> edges[i].to >> edges[i].cost;
    }
    solve();
}

void solve() {
    for (int i = 0; i <= N; i++) par[i] = i;
    sort(edges, edges + M);
    int res = 0;
    for (int i = 0; i < M; i++) {
        Edge e = edges[i];
        if (!same(e.from, e.to)) {
            unite(e.from, e.to);
            res = max(res, e.cost);
        }
    }
    cout << res << endl;
}